package cn.hdu.liang.concurrency;

import java.util.Random;

class ExamFib implements Runnable {

    private final int n;

    public ExamFib(int n) {
        this.n = n;
    }

    @Override
    public void run() {
        System.out.println(getFib(n));
    }

    private String getFib(int n) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++) {
            sb.append(fib(i));
        }
        return sb.toString();
    }

    private int fib(int n) {
        if(n < 2) {
            return 1;
        }
        return fib(n - 2) + fib(n - 1);
    }
}


public class Exam2 {

    public static void main(String[] args) {
        Random random = new Random(System.currentTimeMillis());
        for(int i = 0; i < 100; i++) {
            new Thread(new ExamFib(random.nextInt(40) + 2)).start();
        }
        System.out.println("Main 函数结束");
    }
}
